package com.zqxq.lottery.controller.user;

import com.baomidou.mybatisplus.plugins.Page;
import com.zqxq.common.constant.Result;
import com.zqxq.common.enums.CodeEnum;
import com.zqxq.lottery.entity.bo.user.UserCashBO;
import com.zqxq.lottery.entity.bo.user.UserCashSearchBO;
import com.zqxq.lottery.entity.vo.user.UserCashVO;
import com.zqxq.lottery.service.user.IUserCashService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@Slf4j
public class UserCashController extends UserBaseController{

    @Autowired
    private IUserCashService userCashService;

    //分页查询列表
    @PostMapping("/usercash/page")
    public Result page(@RequestBody UserCashBO search){
        Result rs = new Result();
        try{
            Page page = userCashService.queryPage(search);
            rs.setData(page);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("UserCash Page  Error:",e);
        }
        return rs;
    }
    @PostMapping("/usercash/query")
    public Result query(@RequestBody UserCashSearchBO search){
        Result rs = new Result();
        try{
            List<UserCashVO> list = userCashService.query(search);
            rs.setData(list);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("UserCash Query  Error:",e);
        }
        return rs;
    }
    @PostMapping("/usercash/commission/page")
    public Result pageCommission(@RequestBody UserCashBO search){
        Result rs = new Result();
        try{
            Page page = userCashService.queryCommissionPage(search);
            rs.setData(page);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("UserCash Page  Error:",e);
        }
        return rs;
    }

    //分页查询列表
    @PostMapping("/usercash/pageCZ")
    public Result pageCZ(@RequestBody UserCashBO search){
        Result rs = new Result();
        try{
            Page page = userCashService.queryPageCZ(search);
            rs.setData(page);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("UserCash CZ Page  Error:",e);
        }
        return rs;
    }

    //分页查询列表
    @PostMapping("/usercash/pageTX")
    public Result pageTX(@RequestBody UserCashBO search){
        Result rs = new Result();
        try{
            Page page = userCashService.queryPageTX(search);
            rs.setData(page);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("UserCash TX Page  Error:",e);
        }
        return rs;
    }

    //获取提现详情
    @PostMapping("/usercash/getTX")
    public Result getTX(Long id){
        Result rs = new Result();
        try{
            UserCashVO vo = userCashService.getTX(id);
            rs.setData(vo);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("UserCash TX Page  Error:",e);
        }
        return rs;
    }

    //保存
    @PostMapping("/usercash/save")
    public Result save(@RequestBody UserCashVO vo){
        Result rs = new Result();
        try{
            userCashService.save(vo);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("UserCash Save  Error:",e);
        }
        return rs;
    }

}
